import React, { Component, createRef } from 'react'
// import React, { Component } from 'react'

export default class User3 extends Component {

  // 构造方法
  constructor(props) {
    super(props);
    // 定义一个用户的引用
    this.username = createRef()
  }

  addUser() {
    console.log(this.username.current.value);
  }

  render() {
    return (
      <div>
        <div>
          {/* 非受控组件 */}
          <input type="text" ref={this.username} />
        </div>

        <div>
          <button onClick={this.addUser.bind(this)}>添加用户</button>
        </div>

      </div>
    )
  }





}
